﻿/// Write a program that enters file name along with its full file path (e.g. C:\WINDOWS\win.ini),
/// reads its contents and prints it on the console. Find in MSDN how to use System.IO.File.ReadAllText(…).
/// Be sure to catch all possible exceptions and print user-friendly error messages.



using System;
using System.IO;
using System.Security;


namespace c_sh_II_lek_5_exeptions
{
    class zad3
    {
        static void Main()
        {
            Console.WriteLine("Please, enter file path:");
            try
            {
                string pathFile = Console.ReadLine();
                PrintFile(pathFile);
            }

            catch (ArgumentNullException)
            {
                Console.WriteLine("path is null.");
            }
            catch (ArgumentException)
            {
                Console.WriteLine("path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.");
            }

            catch (PathTooLongException)
            {
                Console.WriteLine(" The specified path, file name, or both exceed\n the system-defined maximum length." +
                    "Path must be\n less than 248 characters, and file names\n must be less than 260 characters.");
            }

            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("The specified path is invalid (for example, it is on an unmapped drive).");
            }

            catch (FileNotFoundException)
            {
                Console.WriteLine("The file specified in path was not found.");
            }

            catch (IOException)
            {
                Console.WriteLine("An I/O error occurred while opening the file.");
            }

            catch (NotSupportedException)
            {
                Console.WriteLine("path is in an invalid format.");
            }

            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("path specified a file that is read-only.\n -or- This operation is not supported on the current platform." +
                    " -or- path specified a directory. -or- The caller does not have the required permission.");
            }

            catch (SecurityException)
            {
                Console.WriteLine("The caller does not have the required permission.");
            }
            
        }
        
        static void PrintFile(string file)
        {
            string content = System.IO.File.ReadAllText(file);
            Console.WriteLine(content);
        }

    }
}
